﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyThongTinNhanKhau.model.DAO
{
    class TienAnTienSuDAO
    {
        SQLServiceDAO service = new SQLServiceDAO();

        internal System.Data.DataTable loadDefault(string maNhanKhau)
        {
            String sql = "select * from NHANKHAU where MaNhanKhau = '" + maNhanKhau + "'";
            DataTable dt = service.getDataTable(sql);
            return dt;
        }

        internal DataTable loadTable(string maNhanKhau)
        {
            String sql = "select MaTienAnTienSu, t.MaNhanKhau, HoTen, CMND, NgayViPham, NoiDung, HinhThucXuLy from NHANKHAU n join TIENANTIENSU t on n.MaNhanKhau = t.MaNhanKhau where n.MaNhanKhau = '"+maNhanKhau+"' and t.TinhTrang = 'Enable'";
            DataTable dt = service.getDataTable(sql);
            return dt;
        }

        internal bool isValidMaTATS(string str)
        {
            String sql = "Select TOP(1) * from TienAnTienSu where MaTienAnTienSu = '" + str + "'";
            DataTable dt = service.getDataTable(sql);

            if (dt.Rows.Count != 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        internal bool themMoiTATS(string maTATS, string maNhanKhau, string ngayViPham, string noiDung, string hinhThucXuLy)
        {
            String sql = "insert into TienAnTienSu values ('" + maTATS + "','" + maNhanKhau + "','" + ngayViPham + "',N'" + noiDung + "',N'" + hinhThucXuLy + "','Enable')";
            return service.executeNonQuery(sql);
        }

        internal bool capNhatTATS(string maTATS, string maNhanKhau, string ngayViPham, string noiDung, string hinhThucXuLy)
        {
            String sql = "update TIENANTIENSU set NgayViPham = '" + ngayViPham + "', NoiDung = N'" + noiDung + "', HinhThucXuLy = N'" + hinhThucXuLy + "' where MaTienAnTienSu = N'" + maTATS + "' and MaNhanKhau = N'" + maNhanKhau + "'";
            return service.executeNonQuery(sql);
        }

        internal bool deleteRow(string maTATS, string maNhanKhau)
        {
            String sql = "update TIENANTIENSU set TinhTrang = 'Disable' where MaTienAnTienSu = '" + maTATS + "' and MaNhanKhau = '" + maNhanKhau + "'";
            return service.executeNonQuery(sql);
        }
    }
}
